#coding:utf-8
"""
新增服务器信息
"""
import database
import web
import public
import new_servicer
import servicer

class main(new_servicer.main):
    """扩展new_servicer.main"""
    def __init__(self):
        self.db=database.database()
        self.render=public.render

    @public.catch_exception
    @public.check_login
    def GET(self):
        user_input=web.input()
        baseinfos=self.get_baseinfos()
        id=user_input.get('id','')
        id=id.strip()
        if id:
            id=int(id)
            servicerinfos=self.get_servicerinfos(id)
            #return str(servicerinfos)
            return self.render.edit_servicer(baseinfos=baseinfos,servicerinfos=servicerinfos)

    @public.catch_exception
    @public.check_login
    def POST(self):
        input_infos=self.get_input_infos()
        sql=r'''UPDATE servicer SET loginstr='%s',place=%s,system=%s,project=%s,sa=%s,ip='%s',comment='%s',type=%s where id = %s'''%(
            input_infos['loginstr'],
            input_infos['place'],
            input_infos['system'],
            input_infos['project'],
            input_infos['sa'],
            input_infos['ip'],
            input_infos['comment'],
            input_infos['type'],
            input_infos['id'],)
        self.db.execute(sql)
        self.db.commit()
        web.seeother('/')

    def get_servicerinfos(self,id):
        """获取服务器的信息"""
        ser=servicer.servicer()
        return ser.get_infos(id)




